﻿using System;
using System.Reflection;

namespace Borg
{
    internal interface IActionInvoker
    {
        object Target { get; }
        MethodInfo Method { get; }
        object[] Args { get; }

        void Invoke();
    }

    internal class ActionInvoker : IActionInvoker
    {
        private readonly Action _action;

        public object Target
        {
            get { return _action.Target; }
        }

        public MethodInfo Method
        {
            get { return _action.Method; }
        }

        public object[] Args
        {
            get { return new object[0]; }
        }

        public ActionInvoker(Action action)
        {
            _action = action;
        }

        public void Invoke()
        {
            _action();
        }
    }

    internal class ActionInvoker<T> : IActionInvoker
    {
        private readonly Action<T> _action;
        private readonly T _args;

        public object Target
        {
            get { return _action.Target; }
        }

        public MethodInfo Method
        {
            get { return _action.Method; }
        }

        public object[] Args
        {
            get { return new object[] { _args }; }
        }

        public ActionInvoker(Action<T> action, T args)
        {
            _action = action;
            _args = args;
        }

        public void Invoke()
        {
            _action(_args);
        }
    }
}
